<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title>首页</title>
    <link href="/css/common.css" rel="stylesheet" type="text/css"/>
    <link href="/css/style.css" rel="stylesheet" type="text/css"/>
    <script src="/js/WebCalendar.js"></script>
    <script th:src="@{js/jquery-1.8.3.js}"></script>
</head>

<body>
<div class="wrap">
    <!-- main begin-->
    <div class="sale">
        <h1 class="lf">在线拍卖系统</h1>
        <div class="logout right"><a href="/layout" title="注销go">注销</a></div>
    </div>
    <div class="forms">
        <form id="form_query" th:action="@{/queryAllAuctions}" method="post">
            <input type="hidden" id="pageNumber" name="pageNum" value="1"/>

            <label for="name">名称</label>
            <input name="auctionname" type="text" class="nwinput" id="name" th:value="${condition.auctionname}"/>

            <label for="names">描述</label>
            <input name="auctiondesc" type="text" id="names" class="nwinput" th:value="${condition.auctiondesc}"/>

            <label for="time">开始时间</label>
            <input name="auctionstarttime"
                   th:value="${#dates.format(condition.auctionstarttime,'yyyy-MM-dd hh:mm:ss')}"
                   type="text" id="time" class="nwinput" readonly="readonly"
                   onclick="selectDate(this,'yyyy-MM-dd hh:mm:ss')"/>

            <label for="end-time">结束时间</label>
            <input name="auctionendtime"
                   th:value="${#dates.format(condition.auctionendtime,'yyyy-MM-dd hh:mm:ss')}"
                   type="text" id="end-time" class="nwinput" readonly="readonly"
                   onclick="selectDate(this,'yyyy-MM-dd hh:mm:ss')"/>

            <label for="price">起拍价</label>
            <input name="auctionstartprice" type="text" id="price" class="nwinput"
                   th:value="${condition.auctionstartprice}"/>
            <input type="submit" value="查询" class="spbg buttombg f14  sale-buttom"/>
        </form>

        <input th:if="${session.user.userisadmin==1}" type="button" value="发布"
               onclick="location.href='/toAddAuctionPage'" class="spbg buttombg f14  sale-buttom buttomb"/>
        <input th:if="${session.user.userisadmin==0}" type="button" value="竞拍结果" onclick="location='/toAuctionResult'"
               class="spbg buttombg f14  sale-buttom buttomb"/>
    </div>
    <div class="items">
        <ul class="rows even strong">
            <li>名称</li>
            <li class="list-wd">描述</li>
            <li>开始时间</li>
            <li>结束时间</li>
            <li>起拍价</li>
            <li class="borderno">操作</li>
        </ul>
        <ul class="rows" th:each=" auction:${auctionList}">
            <li><a href="国书" title="" th:text="${auction.auctionname}"></a></li>
            <li class="list-wd" th:text="${auction.auctiondesc}"></li>
            <li th:text="${#dates.format(auction.auctionstarttime,'yyyy-MM-dd hh:MM:ss')}"></li>
            <li th:text="${#dates.format(auction.auctionendtime,'yyyy-MM-dd hh:MM:ss')}"></li>
            <li th:text="${auction.auctionstartprice}"></li>
            <li class="borderno red">
                <div th:if="${session.user.userisadmin==1}">
                    <a th:href="'/goChange/'+${auction.auctionid}">修改</a>|
                    <!--                    <a th:href="@{/goChange(id=${auction.auctionid})}" >修改</a>|-->
                    <!--                    <img th:src="@{/img/research/{filename}(filename=${research.filename})}">-->
                    <!--                    <a th:href="@{'https://'+${url.url}}" th:text="${url.urlName}"></a>-->
                    <a href="#" th:onclick="'abc('+${auction.auctionid}+')'">删除</a>
                </div>

                <div th:if="${session.user.userisadmin==0}">
                    <a th:href="@{/goAuctionDetail/}+${auction.auctionid}">竞拍</a>
                </div>


            </li>
        </ul>
        <div class="page">
            当前第<span th:text="${page.pageNum}"></span>页,
            总共<span th:text="${page.pages}"></span>页,
            总记录<span th:text="${page.total}"></span>数
            <a href="#" title="" onclick="getPage(1)">首页</a>
            <a href="#" title="" th:onclick="'getPage('+${page.prePage}+')'">上一页</a>
            <!--<span class="red">前5页</span>-->
            <!--<a href="#" title="">1</a>-->
            <!--<a href="#" title="">2</a>-->
            <!--<a href="#" title="">3</a>-->
            <!--<a href="#" title="">4</a>-->
            <!--<a href="#" title="">5</a>-->
            <a href="#" title="" th:onclick="'getPage('+${page.nextPage}+')'">下一页</a>
            <a href="#" title="" th:onclick="'getPage('+${page.pages}+')'">尾页</a>
        </div>
    </div>

    <form action="/deleteAuction" method="post"></form>

    <script>
        function getPage(pageNO) {
            document.getElementById("pageNumber").value = pageNO;
            document.getElementById("form_query").submit();
        }


        function abc(id) {
            if (confirm("你真的确认要删除吗？请确认")) {
                $.ajax({
                    type: "POST",
                    url: '/deleteAuction',
                    data: {
                        auctionid:id
                    },
                    success: function (data) {
                        //
                        if(data.msg==1){
                            alert('删除成功！')
                            location.reload()
                            return true;
                        }else{
                            alert('删除失败！')
                            return false;
                        }
                    },
                    error:function (error){
                        console.log(error)
                        alert('删除失败！')
                    }
                });

            } else {
                return false;
            }

        };

        function dele() {
            if (confirm("你真的确认要修改吗？请确认")) {
                return true;
            } else {
                return false;
            }
        }
    </script>
    <!-- main end-->
</div>
</body>
</html>
